﻿
Partial Class WebForm_ManageMOIExport_EmployeeControl 
    Inherits System.Web.UI.UserControl

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            'Me.BindGV()
        End If
    End Sub

    Public Sub BindGV()
        Dim dat As New clsData
        Dim sql As New MyStringBuilder

        sql.Length = 0



        'If Me.OrgID <> "" Then
        '    sql.AppendFormat(" AND o.UOrganizationID = '{0}' ", Me.OrgID)
        'End If

        'sql.AppendFormat(" UNION ALL ")
        'sql.AppendFormat(" Select son.OrganizationName,v.VolunteerName,v.IdentificationID, ")
        'sql.AppendFormat(" '0' AS IdentificationType,'0' AS HumanType,v.VolunteerID, ")
        'sql.AppendFormat(" v.VolunteerID+'@@' AS [Password],A.MOIValue AS Sex, ")
        'sql.AppendFormat("right('00'+CAST((YEAR(v.BirthDay)-1911) AS VARCHAR)+RIGHT(CONVERT(VARCHAR(12),v.BirthDay,111),6),9) AS Birthday, ")
        'sql.AppendFormat("B.MOIValue AS Occupation,C.MOIValue AS EducationLevel,v.Email,'' AS PeopleNO,  '' AS PositionName, ")
        'sql.AppendFormat(" '' AS RegionID,'' AS VillageID,'' AS [Address],  '' AS OfficePhone,'' AS HomePhone,'' AS MobilePhone  ")
        'sql.AppendFormat(" From OrganizationView father Inner Join OrganizationView son ON father.OrganizationID = son.Parent ")
        'sql.AppendFormat(" Inner join VolunteerLeader v ON son.UOrganizationID=v.UOrganizationID ")
        'sql.AppendFormat(" Left join CodeMapping A ON v.Gender = A.Value And A.TableName='Volunteer' And A.ColumnName='Gender' ")
        'sql.AppendFormat(" Left Join CodeMapping B ON v.OccupationType = B.Value And B.TableName='Volunteer' And B.ColumnName='OccupationType' ")
        'sql.AppendFormat(" Left Join CodeMapping C ON v.EducationLevel = C.Value And C.TableName='Volunteer' And C.ColumnName='EducationLevel' ")
        'sql.AppendFormat(" Where 1=1 ")

        'If Me.OrgID <> "" Then
        '    sql.AppendFormat(" AND father.UOrganizationID = '{0}' ", Me.OrgID)
        'End If

        If Me.OrgID <> "2,-1" Then
            sql.AppendFormat(" Select e.IdentificationID as IdentificationID,e.EmployeeName AS Name,'M' as IDType,'' as ContactPhone, ")
            sql.AppendFormat(" e.IdentificationID AS [UserPassword],'' AS FaxPhone,'' AS CellPhone,case when e.Email<>'' then e.Email else 'vols@tist.com.tw' end as Mail,  '' AS PositionName,'' AS MEMO,o.OrganizationName as Org ")

            sql.AppendFormat(" From OrganizationView o Inner Join Employee e ON e.OrganizationID = o.OrganizationID  ")
            sql.AppendFormat(" Where 1=1 ")
            If Me.OrgID <> "" Then
                sql.AppendFormat(" AND o.UOrganizationID = '{0}' ", Me.OrgID)
            End If
            sql.AppendFormat(" UNION ALL ")
            sql.AppendFormat(" Select v.VolunteerID as IdentificationID,v.VolunteerName AS Name,'M' as IDType,'' as ContactPhone, ")
            sql.AppendFormat(" v.VolunteerID AS [UserPassword],'' AS FaxPhone,'' AS CellPhone,case when v.Email<>'' then v.Email else 'vols@tist.com.tw' end as Mail,  '' AS PositionName,'' AS MEMO,son.OrganizationName  as Org ")

            sql.AppendFormat(" From OrganizationView father Inner Join OrganizationView son ON father.OrganizationID = son.Parent ")

            sql.AppendFormat(" Inner join VolunteerLeader v ON son.UOrganizationID=v.UOrganizationID ")
            sql.AppendFormat(" Where 1=1 ")
        ElseIf Me.OrgID = "2,-1" Then
            sql.AppendFormat(" Select e.IdentificationID as IdentificationID,e.EmployeeName AS Name,'M' as IDType,'' as ContactPhone, ")
            sql.AppendFormat(" e.IdentificationID AS [UserPassword],'' AS FaxPhone,'' AS CellPhone,case when e.Email<>'' then e.Email else 'vols@tist.com.tw' end as Mail,  '' AS PositionName,'' AS MEMO,o.OrganizationName  as Org ")

            sql.AppendFormat(" From OrganizationView o Inner Join Employee e ON e.OrganizationID = o.OrganizationID  ")
            sql.AppendFormat(" Where 1=1 ")
        End If

        If Me.OrgID <> "" AndAlso Me.OrgID <> "2,-1" Then
            sql.AppendFormat(" AND father.UOrganizationID = '{0}' ", Me.OrgID)
        ElseIf Me.OrgID <> "" AndAlso Me.OrgID = "2,-1" Then
            sql.AppendFormat(" AND o.UOrganizationID = '{0}' ", Me.OrgID)
        End If
        EmployeeDT = dat.GetData(sql)
        Me.gv.DataSource = EmployeeDT
        Me.gv.DataBind()

    End Sub

    Protected Sub gv_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gv.PageIndexChanging
        Me.gv.PageIndex = e.NewPageIndex
        Me.BindGV()
    End Sub


    'Protected Sub gv_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gv.RowDataBound
    '    If e.Row.RowType = DataControlRowType.DataRow Then

    '        If CType(e.Row.FindControl("lblBirthDay"), Label).Text <> "" Then
    '            Dim d() As String = CType(e.Row.FindControl("lblBirthDay"), Label).Text.Split(".")     'year=d(0),month=d(1),day=d(2)

    '            '日期格式 099/01/01
    '            If d(0).Length = 2 Then
    '                d(0) = "0" + d(0)
    '            End If

    '            If d(1).Length = 1 Then
    '                d(1) = "0" + d(1)
    '            End If

    '            If d(2).Length = 1 Then
    '                d(2) = "0" + d(2)
    '            End If

    '            CType(e.Row.FindControl("lblBirthDay"), Label).Text = d(0) + "/" + d(1) + "/" + d(2)
    '        End If



    '    End If
    'End Sub

    Public Property EmployeeDT() As Data.DataTable
        Get
            Return ViewState("EmployeeDT")
        End Get
        Set(ByVal value As Data.DataTable)
            ViewState("EmployeeDT") = value
        End Set
    End Property
    Public Property OrgID() As String
        Get
            Return ViewState("OrgID")
        End Get
        Set(ByVal value As String)
            ViewState("OrgID") = value
        End Set
    End Property
End Class
